import { defineStore } from 'pinia';
import { date, useQuasar } from 'quasar';
import {
  createQrCode,
  getChildPartsList,
  getPartDetailData,
  getPartHistoryData,
  editQrCode
} from 'src/services/partsService';
import { Parts } from 'src/services/type';
import {formatDateTimeString, formatTimeString } from 'src/utils/dateUtils';

export const usePartsStore = defineStore('usePartsStore', {
  state: () => ({
    part_id: 0,
    parts: parts,
    childList: [] as Parts[],

    history: [
      {
        id: 1,
        deliver_to: '1',
        check_in_date: '1',
        check_out_date: '1',
      },
    ],
  }),
  getters: {
    isParent: (state)=>state.parts.parent_part==null||state.parts.parent_part==''
  },
  actions: {
    /* update state of itemList sequence */
    
   
    async getPart(id: number) {
      console.log(id);
      
      const res = await getPartDetailData(id);
      console.log(res.data);
      this.parts = res.data
    },

    async getPartHistory() {
      const res = await getPartHistoryData(this.parts.stock_code, this.parts.serial_no);
      this.history = res.data;
    },
    clearParts(){
      this.parts = {...parts}
    }
  }
});

const parts = {
  stock_code: '',
  serial_no: '',
  system: '',
  car: '',
  workgroup: '',
  description: '',
  date_code: '',
  sw_ver: '',
  hw_ver: '',
  assets: '',
  lv1: '',
  lv2: '',
  lv3: '',
  lv4: '',
  lv5: '',
  lv6: '',
  sequence: '',
  qr_code: '',
  create: '',
  last_check_in: '',
  last_check_out: '',
  last_status: '',
  last_status_details: '',
  purchase_date: '',
  image: '',
  io_counter: '',
  detail_description: '',
  deliver_to: '',
  parent_part: '',
};

const clearParts = {
  stock_code: '',
  serial_no: '',
  system: '',
  car: '',
  workgroup: '',
  description: '',
  date_code: '',
  sw_ver: '',
  hw_ver: '',
  assets: '',
  lv1: '',
  lv2: '',
  lv3: '',
  lv4: '',
  lv5: '',
  lv6: '',
  sequence: '',
  qr_code: '',
  create: '',
  last_check_in: '',
  last_check_out: '',
  last_status: '',
  last_status_details: '',
  purchase_date: '',
  image: '',
  io_counter: '',
  detail_description: '',
  deliver_to: '',
  parent_part: '',
};
const cleanQrCode = {
  qr_code: '',
  date: '',
  time: '',
}

const createForm = {
  stock_code: '',
  serial_no: '',
  system: '',
  detail_description: '',
  description: '',
  date_code: '',
  sw_ver: '',
  hw_ver: '',
  equipmentClass: '',
  lv1: '',
  lv2: '',
  lv3: '',
  lv4: '',
  lv5: '',
  parent_part_stock_code: '',
  parent_part_serial_number: '',
};

const clearCreateForm = {
  stock_code: '',
  serial_no: '',
  system: '',
  detail_description: '',
  description: '',
  date_code: '',
  sw_ver: '',
  hw_ver: '',
  equipmentClass: '',
  lv1: '',
  lv2: '',
  lv3: '',
  lv4: '',
  lv5: '',
  parent_part_stock_code: '',
  parent_part_serial_number: '',
};